﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using WindowsGame1.CoreComponents;
using WindowsGame1.ItemClasses;

namespace WindowsGame1
{
    class TreasureScreen : GameScreen
    {
        ButtonMenu menu;
        Texture2D image;
        Texture2D buttonImage;
        SpriteFont spriteFont;
        Vector2 imagePosition;
        Satellite satellite = null;

        public TreasureScreen(Game game)
            : base((Game1)game)
        {
            LoadContent();
            Components.Add(new BackgroundComponent((Game1)game, image, false));
            imagePosition = new Vector2();
            imagePosition.X = (game.Window.ClientBounds.Width - image.Width) / 2;
            imagePosition.Y = (game.Window.ClientBounds.Height - image.Height) / 2;
            string[] items = { "OK" };
            menu = new ButtonMenu((Game1)game, spriteFont, buttonImage);
            menu.SetMenuItems(items);
            Components.Add(menu);
        }

        public int SelectedIndex
        {
            get { return menu.SelectedIndex; }
        }

        public Satellite Satellite
        {
            get { return satellite; }
        }

        protected override void LoadContent()
        {
            image = Content.Load<Texture2D>(@"GUI\treasurebackground");
            buttonImage = Content.Load<Texture2D>(@"GUI\buttonbackgroundshort");
            spriteFont = Content.Load<SpriteFont>(@"normal");
            base.LoadContent();
        }

        public override void Draw(GameTime gameTime)
        {
            base.Draw(gameTime);
            string outstring;
            Vector2 position = new Vector2(15 + imagePosition.X,130 + imagePosition.Y);
            if (satellite != null)
            {
                if (satellite.Gold != 0)
                {
                    outstring = "You found " + satellite.Gold.ToString() + " gold in that chest!";

                    spriteBatch.DrawString(spriteFont,
                    outstring,
                    position,
                    Color.Yellow);
                    position.Y += spriteFont.LineSpacing * 2;

                    if (satellite.Gold > 150)
                    {
                        outstring = "(You got really lucky)";
                        spriteBatch.DrawString(spriteFont, outstring, position, Color.Yellow);
                        position.Y += spriteFont.LineSpacing * 2;
                    }
                }
                if (satellite.Items != null)
                {
                    if (satellite.Gold != 0)
                        outstring = "As well as:";
                    else
                        outstring = "You found:";
                    spriteBatch.DrawString(spriteFont,
                    outstring,
                    position,
                    Color.Yellow);
                    foreach (BaseItem item in satellite.Items)
                    {
                        position.Y += spriteFont.LineSpacing;
                        outstring = " " + item.Name;
                        spriteBatch.DrawString(spriteFont,
                        outstring,
                        position,
                        Color.Yellow);
                    }
                }

            }
        }

        public override void Show()
        {
            satellite = null;
            base.Show();
            menu.Position = new Vector2((image.Width -
            menu.Width) / 2 + imagePosition.X,
            image.Height - menu.Height - 10 + imagePosition.Y);
        }

        public void Show(Satellite satellite)
        {
            Show();
            this.satellite = satellite;
        }

        public override void Hide()
        {
            base.Hide();
            satellite = null;
        }
    }
}
